﻿using System;
using Dexter.CallContext;
using Dexter.Repository.NHibernate.SessionFactory;

namespace Dexter.Repository.NHibernate {
	public class DexterCall :IDexterCall, IDisposable {
		readonly ISessionFactory sessionFactory
		;
		public DexterCall ( ISessionFactory sessionFactory ) {
			this.sessionFactory = sessionFactory;
		}

		public void StartSession ( ) {
			StartSession ( false );
		}

		public void StartSession ( bool isReadOnlyRequest ) {
			sessionFactory.PrepareSesson ( isReadOnlyRequest );
		}

		public void Complete ( bool succesfully ) {
			sessionFactory.CloseCurrentSession ( succesfully );
		}

		public void Dispose() {
			sessionFactory.CloseCurrentSession(false);
		}
	}
}
